import request from '../utils/request'

// 获取地址列表
export const getAddressList = () => {
  return request.get('http://smart-shop.itheima.net/index.php?s=/api/address/list')
}

// 获取默认地址id
export const getDefaultAddressId = () => {
  return request.get('https://smart-shop.itheima.net/index.php?s=/api/address/defaultId')
}
// 获取省市区-添加地址
export const getAreaList = () => {
  return request.get('https://smart-shop.itheima.net/index.php?s=/api/region/tree')
}

// 添加收货地址
// form:{
// name: '张三',
// phone: '13811111111',
// region:[{
//   values:Number,  values:1
//   label:String,  label:'北京市'
// },
// {
//   values:Number,  values:2
//   label:String,  label:'北京市'
// },
// {
//   values:Number,  values:3
//   label:String,  label:'东城区'
// }],
// detail:'南天门'
// }

export const addAddress = (form) => {
  return request.post('http://smart-shop.itheima.net/index.php?s=/api/address/add', form)
}

// 设置默认地址
export const setDefaultAddress = (addressId) => {
  return request.post('https://smart-shop.itheima.net/index.php?s=/api/address/setDefault', { addressId })
}

// 删除收货地址
export const deleteAddress = (addressId) => {
  return request.post('https://smart-shop.itheima.net/index.php?s=/api/address/remove', { addressId })
}

// 获取收货地址详情
export const getAddressDetail = (addressId) => {
  return request.get('https://smart-shop.itheima.net/index.php?s=/api/address/detail', {
    params: {
      addressId
    }
  })
}

// 编辑收货地址
export const editAddress = (addressId, form) => {
  return request.post('https://smart-shop.itheima.net/index.php?s=/api/address/edit', { addressId, form })
}
